/**   
 * Copyright © 2018 eSunny Info. Tech Ltd. All rights reserved.
 * 
 * @Package: com.eastcompeace.swagger 
 * @author: Zousonghua   
 * @date: 2018年4月16日 上午10:42:00 
 */
package com.eastcompeace.swagger;

import java.util.Arrays;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @ClassName: Swagger2
 * @Description: TODO
 * @author: Zousonghua
 * @date: 2018年4月16日 上午10:42:00
 */
@Configuration
@EnableSwagger2
public class Swagger2 {

	@Bean
	public Docket createRestApi() {
		Docket docket = new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
				.apis(RequestHandlerSelectors.basePackage("com.eastcompeace.swagger.web")).paths(PathSelectors.any())
				.build();
		Parameter token = new ParameterBuilder().name("version").description("Version of the api. Starting with 1.")
				.modelRef(new ModelRef("integer")).parameterType("header").defaultValue("1").required(true).build();
		docket.globalOperationParameters(Arrays.asList(token));
		return docket;
	}

	private ApiInfo apiInfo() {
		return new ApiInfoBuilder().title("Spring Boot中使用Swagger2构建Restful Api")
				.description("更多Spring Boot相关文章请关注：http://www.baidu.com/").termsOfServiceUrl("http://www.baidu.com/")
				.contact("zousonghua").version("1.0").build();
	}
}
